
(load "2-2.scm")

(define (rectangle l w)
  (cons l w))

(define (square x) (* x x))

;; 线段长度
(define (segment-length seg)
  (sqrt
   (+
    (square (abs (- (x-point (start-segment seg))
                    (x-point (end-segment seg)))))
    (square (abs (- (y-point (start-segment seg))
                    (y-point (end-segment seg))))))))

;; 面积
(define (area rectangle)
  (* (segment-length (car rectangle))
     (segment-length (cdr rectangle))))
;; 周长
(define (circumference rect)
  (* 2
     (+ (segment-length (car rect))
        (segment-length (cdr rect)))))

(define segment-0-2 (make-segment (make-point 0 0) (make-point 0 2)))
(define segment-1-0 (make-segment (make-point 0 0) (make-point 1 0)))
(define rect-1-2 (rectangle segment-0-2 segment-1-0))

(define segment-0-1 (make-segment (make-point 0 0) (make-point 1 1)))
(define segment-0--1 (make-segment (make-point 0 0) (make-point 1 -1)))
(define rect-1--1 (rectangle segment-0-1 segment-0--1))
